drop if year>2008
gen post=1 if inlist(year,2005,2006,2007,2008)
replace post=1 if year==2004 & inlist(quarter,3,4)
replace post=1 if year==2004 & inlist(quarter,1,2) & inlist(state,"09","10","11","23","24","33","34","36","42")
replace post=1 if year==2004 & inlist(quarter,1,2) & inlist(state,"44","50")
replace post=1 if year==2003 & inlist(quarter,3,4) & inlist(state,"09","10","11","23","24","33","34","36","42")
replace post=1 if year==2003 & inlist(quarter,3,4) & inlist(state,"44","50")
gen east=1 if inlist(state,"01","09","10","11","17","18","19","21","34")
replace east=1 if inlist(state,"23","24","25","26","27","33","36","37","38")
replace east=1 if inlist(state,"39","42","44","45","47","50","51","54","55")
replace east=0 if east==.
replace post=0 if post==.
tostring naics3,replace
merge m:m naics3 using ind3_figure5
keep if _m==3
drop _m

tostring east,gen(eaststr)
gen eastind=eaststr+naics3
drop if state=="29"
gen geo=state
gen postxeast=post*east
gen postxint=post*en_int
gen intxeast=en_int*east
gen postxeastxint=post*east*en_int
gen highint=0
replace highint=1 if en_int>.025
gen postxhigh=post*highint
gen eastxhigh=east*highint
gen postxeastxhigh=post*east*highint
gen fulltemp=1 if year==2000 & quarter==2
egen statetemp=max(fulltemp),by(state)
keep if statetemp==1
gen geoind=geo+"_"+naics3
tostring year quarter,replace
gen yqtr=year+"Q"+quarter
gen ind_qtr=naics3+yqtr
gen state_qtr=state+yqtr
gen state_ind=state+"_"+naics3 
encode ind_qtr, gen(ind_qtrf)
encode state_qtr, gen(state_qtrf)
qui tab state_ind,gen(STinddum)
qui tab yqtr,gen(qtrdum)
qui tab state,gen(statedum)
qui tab naics3,gen(inddum)
gen tempend=empend if year=="2000" & quarter=="2"
egen emp_weight=max(tempend),by(state_ind)
egen temp_avg=mean(empend),by(state_ind)
gen ltemp_avg=ln(temp_avg)
egen lowint_a=min(en_int)
egen highintdiff=max(en_int)
gen intdiff=highintdiff
gen temps=emps if year=="2000" & quarter=="2"
egen emp_weight2=max(temps),by(state_ind)
egen temps_avg=mean(emps),by(state_ind)
gen ltemps_avg=ln(temps_avg)
so state_ind year
egen empweight3t=mean(empend),by(state_ind post)
replace empweight3t=. if post==1
egen empweight3=max(empweight3t),by(state_ind)


so yqtr
encode yqtr, gen(trend)

foreach z of varlist statedum* {
gen trend`z'=`z'*trend
drop `z'
}

foreach z of varlist inddum* {
gen trend`z'=`z'*trend
drop `z'
}

foreach x of varlist qtrdum1-qtrdum44 {
gen eastxhighx`x' = eastxhigh*`x'
gen intxeastx`x' = eastxhigh*`x'*intdiff
}

order intxeastx*
tab naics3,gen(ind)

forvalues i = 1(1)21 {
  qui gen eindtrend`i' = ind`i'*east*trend
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = ind`i'*((east-1)^2)*trend
 }
